// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   IVL_RTO_PQImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.IVL_RTO_PQ;
import com.sunwayhorizo.health.hl7.datatypes.QTY;
import com.sunwayhorizo.health.hl7.datatypes.RTO_PQ;
import com.sunwayhorizo.health.hl7.datatypes.SET_RTO_PQ;
import com.sunwayhorizo.health.hl7.datatypes.ST;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;

import java.util.Set;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            ANYImpl, BLImpl, CSImpl, NullFlavorImpl, 
//            RTO_PQImpl, TYPEImpl

public class IVL_RTO_PQImpl extends ANYImpl
    implements IVL_RTO_PQ
{

    public static final String RCS_ID = "$Header: IVL_RTO_PQImpl.java 115.29 2005/09/16 09:23:43 amchanda noship $";
    protected RTO_PQ _center;
    protected RTO_PQ _high;
    protected BL _highClosed;
    protected RTO_PQ _low;
    protected BL _lowClosed;
    protected RTO_PQ _width;
    private static final IVL_RTO_PQ nullNI = new IVL_RTO_PQImpl(CSImpl.valueOf("NI"));
    private static final IVL_RTO_PQ nullOTH = new IVL_RTO_PQImpl(CSImpl.valueOf("OTH"));
    private static final IVL_RTO_PQ nullNINF = new IVL_RTO_PQImpl(CSImpl.valueOf("NINF"));
    private static final IVL_RTO_PQ nullPINF = new IVL_RTO_PQImpl(CSImpl.valueOf("PINF"));
    private static final IVL_RTO_PQ nullUNK = new IVL_RTO_PQImpl(CSImpl.valueOf("UNK"));
    private static final IVL_RTO_PQ nullASKU = new IVL_RTO_PQImpl(CSImpl.valueOf("ASKU"));
    private static final IVL_RTO_PQ nullNAV = new IVL_RTO_PQImpl(CSImpl.valueOf("NAV"));
    private static final IVL_RTO_PQ nullMSK = new IVL_RTO_PQImpl(CSImpl.valueOf("MSK"));
    private static final IVL_RTO_PQ nullNA = new IVL_RTO_PQImpl(CSImpl.valueOf("NA"));
    private static final IVL_RTO_PQ nullNASK = new IVL_RTO_PQImpl(CSImpl.valueOf("NASK"));

    public static IVL_RTO_PQ nullIVL_RTO_PQ()
    {
        return new IVL_RTO_PQImpl(null);
    }

    public static IVL_RTO_PQ valueOf(RTO_PQ rto_pq, BL bl, RTO_PQ rto_pq1, BL bl1)
    {
        return new IVL_RTO_PQImpl(rto_pq, bl, rto_pq1, bl1);
    }

    private IVL_RTO_PQImpl(CS cs)
    {
        super(true, cs);
        _low = RTO_PQImpl.nullRTO_PQ(NullFlavorImpl.NI);
        _high = RTO_PQImpl.nullRTO_PQ(NullFlavorImpl.NI);
        _lowClosed = BLImpl.nullBL(NullFlavorImpl.NI);
        _highClosed = BLImpl.nullBL(NullFlavorImpl.NI);
    }

    private IVL_RTO_PQImpl(RTO_PQ rto_pq, BL bl, RTO_PQ rto_pq1, BL bl1)
    {
        if(bl == null || rto_pq == null || rto_pq1 == null || bl1 == null)
        {
            if(bl == null)
                throw ANYImpl.newNullException("IVL<RTO_PQ>", "constructor", "lowClosed");
            if(rto_pq == null)
                throw ANYImpl.newNullException("IVL<RTO_PQ>", "constructor", "low");
            if(rto_pq1 == null)
                throw ANYImpl.newNullException("IVL<RTO_PQ>", "constructor", "high");
            if(bl1 == null)
                throw ANYImpl.newNullException("IVL<RTO_PQ>", "constructor", "highClosed");
        }
        _lowClosed = bl;
        _low = rto_pq;
        _high = rto_pq1;
        _highClosed = bl1;
    }

    public INT cardinality()
    {
        throw ANYImpl.newUnsupportedException("IVL<RTO_PQ>", "cardinality");
    }

    public RTO_PQ center()
    {
        throw ANYImpl.newUnsupportedException("IVL<RTO_PQ>", "center");
    }

    public BL contains(RTO_PQ rto_pq)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return low().lessOrEqual(rto_pq).or(low().isNull()).and(rto_pq.lessOrEqual(high()).or(high().isNull())).and(low().equal(rto_pq).implies(lowClosed())).and(high().equal(rto_pq).implies(highClosed()));
    }

    public BL contains(SET_RTO_PQ set_rto_pq)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        if(set_rto_pq instanceof IVL_RTO_PQ)
        {
            IVL_RTO_PQ ivl_rto_pq = (IVL_RTO_PQ)set_rto_pq;
            return contains(ivl_rto_pq.low()).and(contains(ivl_rto_pq.high()));
        }
        if(set_rto_pq instanceof SET_RTO_PQ)
            return contains(((SET_RTO_PQ) (set_rto_pq.hull())));
        else
            return BLImpl.FALSE;
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.IVL_RTO_PQ;
    }

    public RTO_PQ demotion()
    {
        throw ANYImpl.newUnsupportedException("IVL<RTO_PQ>", "demotion");
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof IVL_RTO_PQ))
            return BLImpl.FALSE;
        IVL_RTO_PQ ivl_rto_pq = (IVL_RTO_PQ)any;
        if(isNull().or(any.isNull()).isTrue())
            return BLImpl.FALSE;
        else
            return lowClosed().equal(ivl_rto_pq.lowClosed()).or(lowClosed().isNull().and(ivl_rto_pq.lowClosed().isNull())).and(highClosed().equal(ivl_rto_pq.highClosed()).or(highClosed().isNull().and(ivl_rto_pq.highClosed().isNull()))).and(low().equal(ivl_rto_pq.low()).or(low().isNull().and(ivl_rto_pq.low().isNull()))).and(high().equal(ivl_rto_pq.high()).or(high().isNull().and(ivl_rto_pq.high().isNull())));
    }

    public SET_RTO_PQ except(RTO_PQ rto_pq)
    {
        throw ANYImpl.newUnsupportedException("IVL<RTO_PQ>", "except");
    }

    public SET_RTO_PQ except(SET_RTO_PQ set_rto_pq)
    {
        throw ANYImpl.newUnsupportedException("IVL<RTO_PQ>", "except");
    }

    public RTO_PQ high()
    {
        if(isNull().isTrue())
            return RTO_PQImpl.nullRTO_PQ();
        else
            return _high;
    }

    public BL highClosed()
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return _highClosed;
    }

    public IVL_RTO_PQ hull()
    {
        return this;
    }

    public IVL_RTO_PQ hull(IVL_RTO_PQ ivl_rto_pq)
    {
        throw ANYImpl.newUnsupportedException("IVL<RTO_PQ>", "hull");
    }

    public IVL_RTO_PQ intersection(IVL_RTO_PQ ivl_rto_pq)
    {
        throw ANYImpl.newUnsupportedException("IVL<RTO_PQ>", "intersection");
    }

    public SET_RTO_PQ intersection(SET_RTO_PQ set_rto_pq)
    {
        throw ANYImpl.newUnsupportedException("IVL<RTO_PQ>", "intersection");
    }

    public IVL_RTO_PQ Intersection(IVL_RTO_PQ ivl_rto_pq)
    {
        throw ANYImpl.newUnsupportedException("IVL<RTO_PQ>", "Intersection");
    }

    public BL isEmpty()
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return width().isZero().and(lowClosed().and(highClosed()).not());
    }

    public ST literal()
    {
        throw ANYImpl.newUnsupportedException("IVL<RTO_PQ>", "literal");
    }

    public RTO_PQ low()
    {
        if(isNull().isTrue())
            return RTO_PQImpl.nullRTO_PQ();
        else
            return _low;
    }

    public BL lowClosed()
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return _lowClosed;
    }

    public IVL_RTO_PQ nextAfter(RTO_PQ rto_pq)
    {
        IVL_RTO_PQ ivl_rto_pq = nextTo(rto_pq);
        if(ivl_rto_pq.isNull().isFalse() && ivl_rto_pq.contains(rto_pq).isFalse())
            return this;
        else
            return nullIVL_RTO_PQ();
    }

    public IVL_RTO_PQ nextTo(RTO_PQ rto_pq)
    {
        if(rto_pq.lessOrEqual(high()).isTrue())
        {
            if(rto_pq.equal(high()).isTrue())
            {
                if(highClosed().isFalse())
                    return this;
                else
                    return nullIVL_RTO_PQ();
            } else
            {
                return this;
            }
        } else
        {
            return nullIVL_RTO_PQ();
        }
    }

    public BL nonEmpty()
    {
        return isEmpty().not();
    }

    public BL notEmpty()
    {
        return isEmpty().not();
    }

    public BL overlaps(IVL_RTO_PQ ivl_rto_pq)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return contains(ivl_rto_pq.low()).or(contains(ivl_rto_pq.high())).or(ivl_rto_pq.contains(low())).or(ivl_rto_pq.contains(high()));
    }

    public Set toSet()
    {
        throw ANYImpl.newUnsupportedException("IVL<RTO_PQ>", "toSet");
    }

    public SET_RTO_PQ union(RTO_PQ rto_pq)
    {
        throw ANYImpl.newUnsupportedException("IVL<RTO_PQ>", "union");
    }

    public SET_RTO_PQ union(SET_RTO_PQ set_rto_pq)
    {
        if(set_rto_pq instanceof IVL_RTO_PQ)
        {
            IVL_RTO_PQ ivl_rto_pq = (IVL_RTO_PQ)set_rto_pq;
            if(overlaps(ivl_rto_pq).isTrue())
                return hull(ivl_rto_pq);
        } else
        {
            if(contains(set_rto_pq.hull()).isTrue())
                return this;
            if(set_rto_pq.contains(this).isTrue())
                return set_rto_pq;
        }
        throw ANYImpl.newUnsupportedException("IVL<RTO_PQ>", "union");
    }

    public QTY width()
    {
        if(isNull().isTrue())
            return RTO_PQImpl.nullRTO_PQ();
        if(_width == null)
            _width = (RTO_PQ)_high.minus(_low);
        return _width;
    }

//    public XMLNode[] writeXML(XMLDocument xmldocument, String s)
//        throws Hl7Exception
//    {
//        try
//        {
//            XMLElement xmlelement = null;
//            xmlelement = (XMLElement)xmldocument.createElement(s);
//            if(low() != null && low().isNull().isFalse())
//                xmlelement.appendChild(((RTO_PQImpl)low()).writeXML(xmldocument, "low")[0]);
//            if(high() != null && high().isNull().isFalse())
//                xmlelement.appendChild(((RTO_PQImpl)high()).writeXML(xmldocument, "high")[0]);
//            return (new XMLNode[] {
//                xmlelement
//            });
//        }
//        catch(Exception exception)
//        {
//            throw new Hl7Exception(exception);
//        }
//    }

    public static IVL_RTO_PQ nullIVL_RTO_PQ(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
